<?php

/**
 *
 *
 *
 * @package lib.model
 * @author r9jason
 */
class ApService
{
    public function constructAp()
    {
        $this->constructApAdmin(1000);
        $this->constructApMarketing(2000);
        $this->constructApFinance(3000);
    }

    public function constructApAdmin($seq)
    {
        $lists = array();
        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_ADMIN);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Admin");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_USER_LIST);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_ADMIN);
        $appUserAccess->setMenuLabel("User List");
        $appUserAccess->setMenuUrl("admin/userList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN ."|". AP::AL_USER_LIST);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_USER_ROLE);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_ADMIN);
        $appUserAccess->setMenuLabel("User Role");
        $appUserAccess->setMenuUrl("admin/userRole");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN ."|". AP::AL_USER_ROLE);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_CHANGE_PASSWORD);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_ADMIN);
        $appUserAccess->setMenuLabel("Change Password");
        $appUserAccess->setMenuUrl("admin/changePassword");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN ."|". AP::AL_CHANGE_PASSWORD);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }

    public function constructApMarketing($seq)
    {
        $lists = array();

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_MARKETING);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Marketing");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_MARKETING);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_DIST_LIST);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MARKETING);
        $appUserAccess->setMenuLabel("Distributor List");
        $appUserAccess->setMenuUrl("marketing/distList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_MARKETING ."|". AP::AL_DIST_LIST);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_SPONSOR_TREE);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MARKETING);
        $appUserAccess->setMenuLabel("Sponsor Tree");
        $appUserAccess->setMenuUrl("marketing/sponsorTree");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_MARKETING ."|". AP::AL_SPONSOR_TREE);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_PLACEMENT_TREE);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MARKETING);
        $appUserAccess->setMenuLabel("Placement Tree");
        $appUserAccess->setMenuUrl("marketing/placementTree");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_MARKETING ."|". AP::AL_PLACEMENT_TREE);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ENQUIRY);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MARKETING);
        $appUserAccess->setMenuLabel("Enquiry");
        $appUserAccess->setMenuUrl("marketing/enquiry");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_MARKETING ."|". AP::AL_ENQUIRY);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ANNOUNCEMENT);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MARKETING);
        $appUserAccess->setMenuLabel("Announcement");
        $appUserAccess->setMenuUrl("marketing/announcement");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_MARKETING ."|". AP::AL_ANNOUNCEMENT);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }

    public function constructApFinance($seq)
    {
        $lists = array();

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_FINANCE);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Finance");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ADVANCE_PIN);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("Advance Pin");
        $appUserAccess->setMenuUrl("finance/advancePin");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_ADVANCE_PIN);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_PIN_TRANSACTION);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("Pin Transaction");
        $appUserAccess->setMenuUrl("finance/pinTransaction");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_PIN_TRANSACTION);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_MONTHLY_BONUS);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("Monthly Bonus");
        $appUserAccess->setMenuUrl("finance/monthlyBonus");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_MONTHLY_BONUS);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_DAILY_BONUS);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("Daily Bonus");
        $appUserAccess->setMenuUrl("finance/dailyBonus");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_DAILY_BONUS);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_GOLD_TRADING_HISTORY);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("Gold Trading History");
        $appUserAccess->setMenuUrl("finance/goldTradingHistory");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_GOLD_TRADING_HISTORY);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ECASH_STATEMENT_PERSONAL);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("E-Cash Statement (Personal)");
        $appUserAccess->setMenuUrl("finance/ecashStatementPersonal");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_ECASH_STATEMENT_PERSONAL);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ECASH_STATEMENT_COMPANY);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("E-Cash Statement (Company)");
        $appUserAccess->setMenuUrl("finance/ecashStatementCompany");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_ECASH_STATEMENT_COMPANY);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ECASH_DEPOSIT);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("E-Cash Deposit");
        $appUserAccess->setMenuUrl("finance/ecashDeposit");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_ECASH_DEPOSIT);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ECASH_ADJUSTMENT);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("E-Cash Adjustment");
        $appUserAccess->setMenuUrl("finance/ecashAdjustment");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_ECASH_ADJUSTMENT);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ECASH_WITHDRAWAL);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("E-Cash Withdrawal");
        $appUserAccess->setMenuUrl("finance/ecashWithdrawal");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_ECASH_WITHDRAWAL);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_GOLD_REDEMPTION);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("Gold Redemption");
        $appUserAccess->setMenuUrl("finance/goldRedemption");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_GOLD_REDEMPTION);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_CPS_PRICE_SETTING);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_FINANCE);
        $appUserAccess->setMenuLabel("CPS Price Setting");
        $appUserAccess->setMenuUrl("finance/cpsPriceSetting");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_FINANCE ."|". AP::AL_CPS_PRICE_SETTING);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }
}
